package com.efast.dmom.mes.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.bean.WorkCenter;
import com.efast.dmom.mes.bean.base.IModificationFlags;
import com.efast.dmom.mes.service.WorkCenterService;

@Controller
@RequestMapping("/workCenter")
public class WorkCenterController {
	@Autowired
	private WorkCenterService workCenterService;
	
	@RequestMapping(value = "/operateByWorkCenter")
	public @ResponseBody ResultBean operateByWorkshop(@RequestBody WorkCenter workCenter) {
		ResultBean resultBean = new ResultBean(true, ' ');
		
		// Determine the new
		if (workCenter.getModificationFlag() == IModificationFlags.NEW) {
			resultBean = workCenterService.save(workCenter);
			// Judge update
		} else if (workCenter.getModificationFlag() == IModificationFlags.MODIFIED) {
			resultBean = workCenterService.update(workCenter);
			// Judge to delete
		} else if (workCenter.getModificationFlag() == IModificationFlags.DELETED) {
			resultBean = workCenterService.delete(workCenter);
		}
		return resultBean;
	}

	//get all workCenter
	@RequestMapping(value = "/getAllWorkCenter")
	public @ResponseBody List<WorkCenter> getAllWorkCenter() {
		return workCenterService.getAllWorkCenter();
	}
}
